<?php

require_once 'DAL/class.phpmailer.php';

class AppConfig {

    private static $uploadPath = 'CPS/Server/UPLOAD_FILES/';
    private static $isSendEmail = 1; // set whether to send Email
    private static $DbConfig = [
        'DB_DSN' => 'mysql:host=127.0.0.1;dbname=creditpending',
        'DB_USER' => 'root',
        'DB_PWD' => '1234'
    ];
    // Mime Setting For File Download
    private static $MineTypeConfig = [
        'doc' => 'application/vnd.ms-word',
        'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'pdf' => 'application/pdf',
        'pptx' => 'application/vnd.ms-powerpoint'
    ];

    // the function exposed

    /**
     * Get upload Path
     * @return type
     */
    public static function getUpLoadPath() {
        $documentRoot = $_SERVER['DOCUMENT_ROOT'];
        return $documentRoot . '/' . self::$uploadPath;
    }

    /**
     * Get UUID
     * @return type
     */
    public static function getUniqueId() {
        return md5(date("Y-m-d H:i:s"));
    }

    /**
     * return th DbConfigure
     * @return type
     */
    public static function getDbConfigure() {
        return self::$DbConfig;
    }

    public static function getMineTypeList() {
        return self::$MineTypeConfig;
    }

    /**
     * Send Email
     * @param type $subject
     * @param type $body
     * @param type $toList
     */
    public static function SendMail($subject, $body, $toList) {
        if (self::$isSendEmail) {
            $Mailer = new PHPMailer();
            $Mailer->IsSMTP();  // telling the class to use SMTP
            $Mailer->Host = "smtp.adelaide.edu.au"; // SMTP server
            $Mailer->From = "CreditPendingSystem@adelaide.edu.au";
            $Mailer->FromName = "CreditPendingSystem";
            $Mailer->Subject = $subject;
            $Mailer->WordWrap = 80;
            $Mailer->IsHTML(TRUE);
            $Mailer->Body = $body;
            $arraySize = count($toList);
            for ($i = 0; $i < $arraySize; $i++) {
                $Mailer->AddAddress($toList[$i]['Email'], '');
            }
            $Mailer->Send();
        }
    }

    public static function SendMail2($subject, $body, $toList) {
        if (self::$isSendEmail) {
            $Mailer = new PHPMailer();
            $Mailer->IsSMTP();  // telling the class to use SMTP
            $Mailer->Host = "smtp.adelaide.edu.au"; // SMTP server
            $Mailer->From = $_SESSION["UserEntity"]->UserEmail;
            $Mailer->FromName = $_SESSION["UserEntity"]->UserName;
            $Mailer->Subject = $subject;
            $Mailer->WordWrap = 80;
            $Mailer->IsHTML(TRUE);
            $Mailer->Body = $body;
            $Mailer->AddAddress($toList, '');
            
            return $Mailer->Send();
        }
    }

}

?>
